package com.edu.commons;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.UUID;

/**
 *  加密工具类
 * @Author: whj
 * @Date: 2025/6/17 16:30
 * @Version 1.0
 */
@Slf4j
public class MD5Utils {
    /**
     * 加密的方法
     * @param password 明文密码
     * @param salt 盐值
     * @param times hash次数
     * @return 解密后的密码
     */
    public static String enctype(String password,String salt,int times){
        //新密码的组合方式
        password = salt+password+salt+password+salt;
        for (int result = 0; result < times; result++) {
            password = DigestUtils.md5DigestAsHex(password.getBytes(StandardCharsets.UTF_8));
        }
        return password;
    }

    public static void main(String[] args) {
        //生成salt
        String salt  = UUID.randomUUID().toString().replace("-","");
        System.out.println("salt:"+salt);
        String password = enctype("123123", salt, 8);
        System.out.println("password:"+password);
    }
}
